package com.fivefu.core.skyeye.event.config;

import com.fivefu.core.module.auth.properties.AuthClientProperties;
import com.fivefu.core.skyeye.event.filter.LoginHandlerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @author ：DELL
 * @description：TODO
 * @date ：2020/2/15 19:40
 */
@Configuration
public class CameraWebMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private LoginHandlerInterceptor loginHandlerInterceptor;

    @Autowired
    private AuthClientProperties authClientProperties;

    /*//默认首页
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("doc.html");
        registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
    }
    //静态资源
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }*/

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加登录拦截
        InterceptorRegistration LoginRegistration = registry.addInterceptor(loginHandlerInterceptor);
        LoginRegistration.addPathPatterns("/**");
        String[] openUrls = authClientProperties.getOpenUrls();
        //添加不拦截路径
        if (openUrls != null) {
            LoginRegistration.excludePathPatterns(
                    openUrls
                    //swagger 限制
                /*"/",
                "/**.html",
                "/webjars/**",
                "/swagger-resources/**",
                "/v3/api-docs",

                "/oauth2/**",
                 "/favicon.ico"*/
            );
        }
    }



}

